import { CommonModel, ListResponse, PagerQuery } from '.'
import { authorizeRequest } from '../util/http'

const ROUTE = 'v1/favorites'

export type FavoriteListResponse = ListResponse<Favorite>
export interface Favorite extends CommonModel {
    name: string;
    desc: string;
    userId: number;
}
export const apiGetFavoriteList = async (pager?: PagerQuery) => {
    return (await authorizeRequest.get<FavoriteListResponse>(ROUTE, { params: pager })).data
}
export interface CreateFavoriteRequest {
    name: string;
    desc: string;
}
export const apiPostFavorite = async (params: CreateFavoriteRequest) => {
    return (await authorizeRequest.post<object>(ROUTE, params)).data
}
export interface UpdateFavoriteRequest {
    id: number
    name: string;
    desc: string;
}
export const apiPutFavorite = async (params: UpdateFavoriteRequest) => {
    return (await authorizeRequest.put<object>(ROUTE + '/' + params.id, params)).data
}
export interface DeleteFavoriteRequest {
    id: number
}
export const apiDeleteFavorite = async (params: DeleteFavoriteRequest) => {
    return (await authorizeRequest.delete<object>(ROUTE + '/' + params.id)).data
}